import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class FunctionalInterfaceDemo {
    public static void main(String[] args) {
        ArrayList<String> alt = new ArrayList<>();
        alt.add("ccc");
        alt.add("dd");
        alt.add("aaaa");
        alt.add("b");
        System.out.println("Before sorting : " + alt);
        //Collections.sort(alt);//不使用比较器，默认字典序排序
        Collections.sort(alt,getComparator());
        System.out.println("After sorting : " + alt);

    }
    private static Comparator<String> getComparator(){  //返回一个函数式接口
        return (s1,s2)-> s1.length() - s2.length();  //按字符串长度进行排序
    }
}